#ifndef PARSE_H_INCLUDED
#define PARSE_H_INCLUDED
#include "minidbms.h"
#include <algorithm>
#include <boost/regex.hpp>
#include <cctype>
#include <string>
#include <map>
using namespace boost;

void parse(string name);

enum
{NAME,TABLE,FIELDNAME,ALIAS,NUMBER,STRING,CMP,CMPSELECT,
AND,OR,CMP_INT,CMP_STRING,CMP_SELECT,CMP_LIKE,WHERE,ORDERBY,
GROUPBY,DISTINCT,LIKE,JOIN,ONEXPR,SELECT,SELECTALL,COLUMN,
INSERTCOLS,VALUES,INSERTVALS,ASSIGN,ASSIGNINT,ASSIGNSTRING,
UPDATE,DELETEONE,STARTCOL,COLUMNDEF,ATTR,PRIKEY,DEFAULT,
CREATE,CREATEDATABASE,USEDATABASE,STMT,CONDITION};

struct Sub_Stmt
{//This is a structure to save all querys
    int type;
};
struct Name_Stmt:Sub_Stmt
{//if a parsed query is a column name, it will be saved by this
    string name;
    bool AnyAlias;
    string Alias;
    bool IsAll;
};
struct Table_Stmt:Sub_Stmt
{//Name of a Table
    string table;
};
struct FieldName_Stmt:Sub_Stmt
{//A specific attribute in a specific table
    string name;
    string table;
};
struct Number_Stmt:Sub_Stmt
{//A int type data
    int num;
};
struct String_Stmt:Sub_Stmt
{//A varchar type data
    string str;
};
struct Values_Stmt:Sub_Stmt
{//A value List
    list<Sub_Stmt*> value;
};
struct Column_Stmt:Sub_Stmt
{//name of column
    string Columnname;
};
struct ColumnName_Stmt:Sub_Stmt
{//A column name list
    list<string> Columnname;
};
struct Insert_Stmt:Sub_Stmt
{//An insert query
    string table;
    ColumnName_Stmt Name;
    Values_Stmt Value;
	bool AnyName;
};
struct Columndef_Stmt:Sub_Stmt
{//Column Defination for Create
    string Name;
    DataType ColumnType;
    int Size;
    bool IsPrimary;
};
struct Create_Stmt:Sub_Stmt
{
    string table;
    list<Columndef_Stmt*> Column;
};

struct Alias_Stmt:Sub_Stmt
{
  string table;
  string attr;
};

struct Condition_Stmt:Sub_Stmt
{
  Alias_Stmt cond1;
  int symbol;// > <  = <>  only these 4 condition,0 1 2 3 to represent
  Sub_Stmt* cond2; //cond 2  may be alias_stmt or sting ,int
};

struct Select_Stmt:Sub_Stmt
{
  int SelectType; // common:0 count:1 sum:2
  list<string> AttrName; //up to 5attribute
  list<string> TableName; //up to 2 tables
  list<Condition_Stmt*> WhereCond;
  list<int> Relation; //"AND":0 "OR":1   length reation = length wherecond-1
  map<string,string> originname;//A as B: originname["B"] = "A"
};
#endif // PARSE_H_INCLUDED
